home *** CD-ROM | disk | FTP | other *** search
/ PC PowerPlay 22 / PCPP #22.iso / Quake2 / q2source_12_11 / utils3 / bsp / qbsp3 / leakfile.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-09  |  1.6 KB  |  80 lines

  1.  
  2. #include "qbsp.h"
  3.  
  4. /*
  5. ==============================================================================
  6.  
  7. LEAF FILE GENERATION
  8.  
  9. Save out name.line for qe3 to read
  10. ==============================================================================
  11. */
  12.  
  13.  
  14. /*
  15. =============
  16. LeakFile
  17.  
  18. Finds the shortest possible chain of portals
  19. that leads from the outside leaf to a specifically
  20. occupied leaf
  21. =============
  22. */
  23. void LeakFile (tree_t *tree)
  24. {
  25.     vec3_t    mid;
  26.     FILE    *linefile;
  27.     char    filename[1024];
  28.     node_t    *node;
  29.     int        count;
  30.  
  31.     if (!tree->outside_node.occupied)
  32.         return;
  33.  
  34.     qprintf ("--- LeakFile ---\n");
  35.  
  36.     //
  37.     // write the points to the file
  38.     //
  39.     sprintf (filename, "%s.lin", source);
  40.     linefile = fopen (filename, "w");
  41.     if (!linefile)
  42.         Error ("Couldn't open %s\n", filename);
  43.  
  44.     count = 0;
  45.     node = &tree->outside_node;
  46.     while (node->occupied > 1)
  47.     {
  48.         int            next;
  49.         portal_t    *p, *nextportal;
  50.         node_t        *nextnode;
  51.         int            s;
  52.  
  53.         // find the best portal exit
  54.         next = node->occupied;
  55.         for (p=node->portals ; p ; p = p->next[!s])
  56.         {
  57.             s = (p->nodes[0] == node);
  58.             if (p->nodes[s]->occupied
  59.                 && p->nodes[s]->occupied < next)
  60.             {
  61.                 nextportal = p;
  62.                 nextnode = p->nodes[s];
  63.                 next = nextnode->occupied;
  64.             }
  65.         }
  66.         node = nextnode;
  67.         WindingCenter (nextportal->winding, mid);
  68.         fprintf (linefile, "%f %f %f\n", mid[0], mid[1], mid[2]);
  69.         count++;
  70.     }
  71.     // add the occupant center
  72.     GetVectorForKey (node->occupant, "origin", mid);
  73.  
  74.     fprintf (linefile, "%f %f %f\n", mid[0], mid[1], mid[2]);
  75.     qprintf ("%5i point linefile\n", count+1);
  76.  
  77.     fclose (linefile);
  78. }
  79.  
  80.